package com.kocel.block.repository;

import com.kocel.block.model.TbBlockInventory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface TbBlockInventoryRepository extends JpaRepository<TbBlockInventory,String> {

    @Query("select b from TbBlockInventory b where 1 = 1")
    List<TbBlockInventory> findAll();

    List<TbBlockInventory> findByProductContaining(String product);

    List<TbBlockInventory> findByBlockNumberContaining(String blockNumber);

    List<TbBlockInventory> findByMeltingStoveContaining(String meltingStove);

    boolean existsByBlockNumber(String blockNumber);

    List<TbBlockInventory> findAllByMeltingStove(String meltingStove);

    List<TbBlockInventory> findByStateIsNot(String state);

    @Query("from TbBlockInventory as m where m.state <> '1'")
    List<TbBlockInventory> findForOut1(String blockNumber);

    @Query("from TbBlockInventory as m where m.state <> '1' and (m.blockNumber = ?1 or m.product = ?1 or m.meltingStove = ?1 or m.castingNum = ?1 ) order by m.remark desc ")
    List<TbBlockInventory> findForOut2(String blockNumber);

    @Query("from TbBlockInventory as m where m.state <> '1' and m.destroyTime < CURRENT_DATE()")
    List<TbBlockInventory> findForDestroy1(String blockNumber);

    @Query("from TbBlockInventory as m where m.state <> '1' and m.destroyTime < CURRENT_DATE() and (m.blockNumber like %?1% or m.product like %?1% or m.meltingStove like %?1% or m.castingNum like %?1% ) order by  m.storageTime desc")
    List<TbBlockInventory> findForDestroy2(String blockNumber);
}
